package com.example.game_forum.controller;

import com.example.game_forum.dto.TCommentContentDto;
import com.example.game_forum.dto.TPostContentDto;
import com.example.game_forum.dto.TPostTitleDto;
import com.example.game_forum.service.TCommentService;
import com.example.game_forum.service.TPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@AllArgsConstructor
@RestController
@RequestMapping("/api/t-post")
@Tag(name = "公共帖子管理", description = "公共帖子接口")
public class CommonPostController {
    private final TPostService postService;
    private final TCommentService commentService;

    @Operation(
            summary = "获取板块帖子列表",
            description = "根据板块类型查询帖子标题列表"
    )
    @ApiResponse(
            responseCode = "200",
            description = "成功获取帖子列表",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = TPostTitleDto.class)
            )
    )
    @GetMapping("/list/type")
    public ResponseEntity<List<TPostTitleDto>> getPostTitlesByPostType(@RequestParam String postType) {
        return ResponseEntity.ok(postService.getPostTitlesByPostType(postType));
    }

    @Operation(
            summary = "搜索帖子",
            description = "根据帖子标题模糊查询"
    )
    @ApiResponse(
            responseCode = "200",
            description = "成功查询帖子",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = TPostTitleDto.class)
            )
    )
    @GetMapping("/search")
    public ResponseEntity<List<TPostTitleDto>> searchPostTitlesByTitle(@RequestParam String title) {
        return ResponseEntity.ok(postService.searchPostsByTitle(title));
    }

    @Operation(
            summary = "查询用户发布的帖子",
            description = "根据用户id查询"
    )
    @ApiResponse(
            responseCode = "200",
            description = "成功查询帖子",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = TPostTitleDto.class)
            )
    )
    @GetMapping("/list/userid")
    public ResponseEntity<List<TPostTitleDto>> getPostTitlesByUserId(@RequestParam String userId) {
        return ResponseEntity.ok(postService.getPostTitleByUserId(userId));
    }

    @Operation(
            summary = "获取帖子详情",
            description = "根据帖子ID查询帖子详细内容"
    )
    @ApiResponse(
            responseCode = "200",

            description = "成功获取帖子详情",
            content = @Content(
                    mediaType = "application/json",
                    schema = @Schema(implementation = TPostContentDto.class)
            )
    )
    @GetMapping("/content")
    public ResponseEntity<TPostContentDto> getPostContentById(@RequestParam String postId) {
        return ResponseEntity.ok(postService.getPostContentById(postId));
    }

    @GetMapping("/list")
    public ResponseEntity<List<TCommentContentDto>> getCommentsByPostId(@RequestParam String postId) {
        return ResponseEntity.ok(commentService.getCommentsByPostId(postId));
    }
}
